<?php
namespace App\Http\Controllers\ShopApi\V1\Account;

use App\Http\Controllers\ShopApiController;
use App\Http\Controllers\Business\Shop\V1\Account\Account;


class AccountController extends ShopApiController
{
    //财务首页
    public function index() {
        $shopId = $this->request->get('shopid');
        $startTime = $this->request->get('starttime');
        $lastTime = $this->request->get('lasttime');
        $result = Account::index($shopId, $startTime, $lastTime);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        }
        $data = $result['data'];
        return $this->responseSuccessData($data);
    }
    //财务订单列表
    public function waitList() {
        $shopId = $this->request->get('shopid');
        $result = Account::waitList($shopId);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        }
        $data = $result['data'];
        return $this->responseSuccessData($data);
    }
    //财务订单列表
    public function receiptList() {
        $shopId = $this->request->get('shopid');
        $result = Account::receiptList($shopId);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        }
        $data = $result['data'];
        return $this->responseSuccessData($data);
    }
    //财务订单列表
    public function orderListByDate() {
        $shopId = $this->request->get('shopid');
        $myDate = $this->request->get('mydate');
        $result = Account::orderListByDate($shopId, $myDate);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        }
        $data = $result['data'];
        return $this->responseSuccessData($data);
    }
    //订单详情
    public function orderDetail() {
        $shopId = $this->request->get('shopid');
        $orderNumber = $this->request->get('ordernumber');
        $result = Account::orderDetails($shopId, $orderNumber);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        }
        $data = $result['data'];
        return $this->responseSuccessData($data);
    }
    //地推结款, 首页
    public function salesmanIndex() {
        $shopId = $this->request->get('shopid');
        if($this->request->has('page')) {
            $page = $this->request->get('page');
        } else {
            $page = 1;
        }
        $result = Account::salesmanIndex($shopId, $page);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        }
        $data = $result['data'];
        return $this->responseSuccessData($data);
    }
    //地推待提现
    public function salesmanWaitWithdrawalList() {
        $shopId = $this->request->get('shopid');
        if($this->request->has('page')) {
            $page = $this->request->get('page');
        } else {
            $page = 1;
        }
        if(!$this->request->has('apiversion')) {
            //老版本
            $result = Account::salesmanWaitWithdrawalList($shopId, $page);
        } else {
            //新版本
            $apiVersion = $this->request->get('apiversion');
            if($apiVersion == 'v2') {
                $result = Account::salesmanWaitWithdrawalListByV2Version($shopId, $page);
            } else {
                return $this->responseError('版本号不支持');
            }
        }
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        }
        return $this->responseSuccessData($result['data']);
    }
    //地推结算方式
    public function salesmanPayMethod() {
        $shopId = $this->request->get('shopid');
        $result = Account::salesmanPayMethod($shopId);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        }
        return $this->responseSuccessData($result['data']);
    }
    //地推已提现
    public function salesmanWithdrawalList() {
        $shopId = $this->request->get('shopid');
        $date = $this->request->get('selectdate'); //TODO
        if($this->request->has('page')) {
            $page = $this->request->get('page');
        } else {
            $page = 1;
        }
        $result = Account::salesmanWithdrawalList($shopId, $date, $page);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        }
        return $this->responseSuccessData($result['data']);
    }
}